home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 676-700 / 681 / term / source.lha / termInit.c < prev    next >
C/C++ Source or Header  |  1992-05-09  |  45KB  |  2,092 lines

  1. /*
  2. **    $Id: termInit.c,v 1.10 92/05/05 18:11:55 olsen Sta Locker: olsen $
  3. **    $Revision: 1.10 $
  4. **    $Date: 92/05/05 18:11:55 $
  5. **
  6. **    Program initialization and shutdown routines
  7. **
  8. **    Copyright © 1990-1992 by Olaf `Olsen' Barthel & MXM
  9. **        All Rights Reserved
  10. */
  11.  
  12. #include "termGlobal.h"
  13.  
  14. #include "OwnDevUnit.h"
  15.  
  16.     /* Screen title. */
  17.  
  18. STATIC UBYTE ScreenTitle[80];
  19.  
  20.     /* A couple of private strings which are to `impersonate' the
  21.      * control sequences associated with the four function keys.
  22.      */
  23.  
  24. STATIC UBYTE *FunctionKeyCodes[4] =
  25. {
  26.     "\\eOP",
  27.     "\\eOQ",
  28.     "\\eOR",
  29.     "\\eOS"
  30. };
  31.  
  32.     /* This variable helps us to remember whether the fast!
  33.      * macro panel was open or not.
  34.      */
  35.  
  36. STATIC BYTE HadFastMacros = FALSE;
  37.  
  38.     /* ProcessCleanup(register __d1 BPTR SegList):
  39.      *
  40.      *    Frees all resource the main process has allocated when
  41.      *    it exits.
  42.      */
  43.  
  44. STATIC VOID __saveds __asm
  45. ProcessCleanup(register __d1 BPTR SegList)
  46. {
  47.     CloseAll();
  48.  
  49.     Forbid();
  50.  
  51.     UnLoadSeg(SegList);
  52.  
  53.     CloseLibrary(DOSBase);
  54. }
  55.  
  56.     /* SegmentSplit(STRPTR Name,BYTE Pri,LONG StackSize,APTR Function):
  57.      *
  58.      *    Create a new process from the current one.
  59.      */
  60.  
  61. struct Process *
  62. SegmentSplit(STRPTR Name,BYTE Pri,LONG StackSize,APTR Function)
  63. {
  64.     struct Process            *Child;
  65.     struct CommandLineInterface    *CLI;
  66.  
  67.     CLI = (struct CommandLineInterface *)BADDR(((struct Process *)SysBase -> ThisTask) -> pr_CLI);
  68.  
  69.     if(Child = CreateNewProcTags(
  70.         NP_CommandName,    "term",
  71.         NP_Name,    Name,
  72.         NP_Priority,    Pri,
  73.         NP_StackSize,    StackSize,
  74.         NP_Entry,    Function,
  75.         NP_Cli,        TRUE,
  76.         NP_ExitCode,    ProcessCleanup,
  77.         NP_ExitData,    CLI -> cli_Module,
  78.     TAG_DONE))
  79.     {
  80.         CLI -> cli_Module = NULL;
  81.  
  82.         return(Child);
  83.     }
  84.     else
  85.         return(NULL);
  86. }
  87.  
  88.     /* ConfigSetup():
  89.      *
  90.      *    Compare the current configuration with the
  91.      *    last backup and reset the serial device, terminal,
  92.      *    etc. if necessary.
  93.      */
  94.  
  95. VOID
  96. ConfigSetup()
  97. {
  98.     BYTE NewEmulation = FALSE;
  99.  
  100.     if(Config . OpenFastMacroPanel)
  101.         HadFastMacros = TRUE;
  102.  
  103.     if(!Config . BufferEnabled)
  104.         BufferFrozen = TRUE;
  105.  
  106.     if(Menu)
  107.     {
  108.         struct MenuItem *SomeItem;
  109.  
  110.         if(SomeItem = FindThisItem(MEN_FREEZEBUFFER))
  111.         {
  112.             if(BufferFrozen)
  113.                 SomeItem -> Flags |= CHECKED;
  114.             else
  115.                 SomeItem -> Flags &= ~CHECKED;
  116.         }
  117.     }
  118.  
  119.     if(PrivateConfig . SerBuffSize != Config . SerBuffSize)
  120.     {
  121.         if(StripBuffer)
  122.             FreeVec(StripBuffer);
  123.  
  124.         if(!(StripBuffer = (UBYTE *)AllocVec(Config . SerBuffSize,MEMF_ANY)))
  125.             MyEasyRequest(Window,LocaleString(MSG_GLOBAL_TERM_HAS_A_PROBLEM_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),LocaleString(MSG_GLOBAL_NO_AUX_BUFFERS_TXT));
  126.     }
  127.  
  128.     if(Stricmp(PrivateConfig . FastMacroFile,Config . FastMacroFile))
  129.         LoadFastMacros(Config . FastMacroFile);
  130.  
  131.         /* No custom keymap this time? */
  132.  
  133.     if(!Config . KeyMapName[0])
  134.     {
  135.         KeyMap = NULL;
  136.  
  137.         if(KeySegment)
  138.         {
  139.             UnLoadSeg(KeySegment);
  140.  
  141.             KeySegment = NULL;
  142.         }
  143.     }
  144.     else
  145.     {
  146.             /* Check whether the keymap name has changed. */
  147.  
  148.         if(Stricmp(PrivateConfig . KeyMapName,Config . KeyMapName))
  149.         {
  150.             struct KeyMapResource *KeyMapResource;
  151.  
  152.                 /* Reset keymap pointer. */
  153.  
  154.             KeyMap = NULL;
  155.  
  156.                 /* Try to get access to the list of currently loaded
  157.                  * keymap files.
  158.                  */
  159.  
  160.             if(KeyMapResource = (struct KeyMapResource *)OpenResource("keymap.resource"))
  161.             {
  162.                 struct KeyMapNode *Node;
  163.  
  164.                     /* Try to find the keymap in the list. */
  165.  
  166.                 Forbid();
  167.  
  168.                 if(Node = (struct KeyMapNode *)FindName(&KeyMapResource -> kr_List,FilePart(Config . KeyMapName)))
  169.                     KeyMap = &Node -> kn_KeyMap;
  170.  
  171.                 Permit();
  172.             }
  173.  
  174.                 /* Still no keymap available? */
  175.  
  176.             if(!KeyMap)
  177.             {
  178.                 APTR OldPtr = ThisProcess -> pr_WindowPtr;
  179.  
  180.                     /* Disable DOS requesters. */
  181.  
  182.                 ThisProcess -> pr_WindowPtr = (APTR)-1;
  183.  
  184.                     /* Unload the old keymap code. */
  185.  
  186.                 if(KeySegment)
  187.                     UnLoadSeg(KeySegment);
  188.  
  189.                     /* Try to load the keymap from the
  190.                      * name the user entered.
  191.                      */
  192.  
  193.                 if(!(KeySegment = LoadSeg(Config . KeyMapName)))
  194.                 {
  195.                         /* Second try: load it from
  196.                           * the standard keymaps drawer.
  197.                           */
  198.  
  199.                     strcpy(SharedBuffer,"Devs:Keymaps");
  200.  
  201.                     if(AddPart(SharedBuffer,FilePart(Config . KeyMapName),256))
  202.                         KeySegment = LoadSeg(SharedBuffer);
  203.                 }
  204.  
  205.                     /* Did we get the keymap file? */
  206.  
  207.                 if(KeySegment)
  208.                 {
  209.                     struct KeyMapNode *Node = (struct KeyMapNode *)&((ULONG *)BADDR(KeySegment))[1];
  210.  
  211.                     KeyMap = &Node -> kn_KeyMap;
  212.                 }
  213.  
  214.                     /* Enable DOS requesters again. */
  215.  
  216.                 ThisProcess -> pr_WindowPtr = OldPtr;
  217.             }
  218.         }
  219.     }
  220.  
  221.     if(Stricmp(PrivateConfig . MacroFile,Config . MacroFile))
  222.     {
  223.         if(!LoadMacros(Config . MacroFile,MacroKeys))
  224.         {
  225.             WORD i,j;
  226.  
  227.             for(j = 0 ; j < 4 ; j++)
  228.             {
  229.                 for(i = 0 ; i < 10 ; i++)
  230.                     MacroKeys -> Keys[j][i][0] = 0;
  231.             }
  232.  
  233.             for(i = 0 ; i < 4 ; i++)
  234.                 strcpy(MacroKeys -> Keys[1][i],FunctionKeyCodes[i]);
  235.         }
  236.         else
  237.             strcpy(LastMacros,Config . MacroFile);
  238.     }
  239.  
  240.     if(PrivateConfig . Font != Config . Font)
  241.     {
  242.         if(Config . Font == FONT_IBM && IBM)
  243.             CurrentFont = IBM;
  244.         else
  245.             CurrentFont = Topaz;
  246.  
  247.         SetFont(RPort,CurrentFont);
  248.     }
  249.  
  250.     if(PrivateConfig . DisplayMode != Config . DisplayMode || PrivateConfig . ColourMode != Config . ColourMode)
  251.         ResetDisplay = TRUE;
  252.  
  253.     if(PrivateConfig . ColourMode == COLOUR_EIGHT && Config . ColourMode == COLOUR_EIGHT)
  254.     {
  255.         if((PrivateConfig . DisableBlinking & ~TERMINAL_FASTER) != (Config . DisableBlinking & ~TERMINAL_FASTER))
  256.             ResetDisplay = TRUE;
  257.     }
  258.  
  259.     if((PrivateConfig . DisableBlinking & TERMINAL_FASTER) != (Config . DisableBlinking & TERMINAL_FASTER))
  260.         ResetDisplay = TRUE;
  261.  
  262.     if(PrivateConfig . StatusLine != Config . StatusLine)
  263.         ResetDisplay = TRUE;
  264.  
  265.     if(PrivateConfig . TitleBar != Config . TitleBar)
  266.         ResetDisplay = TRUE;
  267.  
  268.     if(strcmp(PrivateConfig . Protocol,Config . Protocol))
  269.     {
  270.         strcpy(LastXprLibrary,Config . Protocol);
  271.  
  272.         ProtocolSetup();
  273.     }
  274.  
  275.         /* Serial configuration needs updating? */
  276.  
  277.     if(!SerialSet && (memcmp(&PrivateConfig,&Config,offsetof(struct Configuration,ModemInit)) || PrivateConfig . SerBuffSize != Config . SerBuffSize))
  278.     {
  279.         BYTE SameDevice = TRUE;
  280.  
  281.             /* Any device name change? */
  282.  
  283.         if(strcmp(PrivateConfig . SerialDevice,Config . SerialDevice))
  284.             SameDevice = FALSE;
  285.         else
  286.         {
  287.             if(PrivateConfig . SerBuffSize != Config . SerBuffSize)
  288.                 SameDevice = FALSE;
  289.  
  290.                 /* Handshaking mode changed to RTS/CTS protocol? */
  291.  
  292.             if(PrivateConfig . Handshaking != HANDSHAKING_RTSCTS && PrivateConfig . Handshaking != HANDSHAKING_RTSCTS_DSR && (Config . Handshaking == HANDSHAKING_RTSCTS || Config . Handshaking == HANDSHAKING_RTSCTS_DSR))
  293.                 SameDevice = FALSE;
  294.  
  295.             if((PrivateConfig . Handshaking == HANDSHAKING_RTSCTS && Config . Handshaking == HANDSHAKING_RTSCTS_DSR) || (PrivateConfig . Handshaking == HANDSHAKING_RTSCTS_DSR && Config . Handshaking == HANDSHAKING_RTSCTS))
  296.                 SameDevice = FALSE;
  297.         }
  298.  
  299.         if(ReadRequest)
  300.         {
  301.                 /* Stop any IO activity. */
  302.  
  303.             ClearSerial();
  304.         }
  305.         else
  306.             SameDevice = FALSE;
  307.  
  308.             /* No dramatic changes? Simply change the parameters. */
  309.  
  310.         if(SameDevice)
  311.         {
  312.                 /* Use new parameters... */
  313.  
  314.             SetFlags(WriteRequest);
  315.             SetFlags(ReadRequest);
  316.  
  317.                 /* ...and set them. */
  318.  
  319.             WriteRequest -> IOSer . io_Command = SDCMD_SETPARAMS;
  320.  
  321.             DoIO(WriteRequest);
  322.  
  323.                 /* Restart read request. */
  324.  
  325.             ReadRequest -> IOSer . io_Command    = CMD_READ;
  326.             ReadRequest -> IOSer . io_Data        = ReadBuffer;
  327.             ReadRequest -> IOSer . io_Length    = 1;
  328.  
  329.             SetSignal(0,SIG_SERIAL);
  330.  
  331.             SendIO(ReadRequest);
  332.         }
  333.         else
  334.         {
  335.             UBYTE *Error;
  336.  
  337.             DeleteSerial();
  338.  
  339.             if(Error = CreateSerial())
  340.             {
  341.                 MyEasyRequest(Window,LocaleString(MSG_GLOBAL_TERM_HAS_A_PROBLEM_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),Error);
  342.  
  343.                 DeleteSerial();
  344.             }
  345.             else
  346.             {
  347.                 if(SerialMessage)
  348.                 {
  349.                     MyEasyRequest(Window,LocaleString(MSG_GLOBAL_TERM_HAS_A_PROBLEM_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),SerialMessage);
  350.  
  351.                     SerialMessage = NULL;
  352.                 }
  353.             }
  354.         }
  355.     }
  356.  
  357.     if(!ResetDisplay && memcmp(&PrivateConfig . Colours[0],&Config . Colours[0],sizeof(UWORD) * 16))
  358.     {
  359.         WORD i;
  360.  
  361.         for(i = 0 ; i < 16 ; i++)
  362.             BlinkColours[i] = Config . Colours[i];
  363.  
  364.         LoadRGB4(VPort,&Config . Colours[0],(1 << Screen -> RastPort . BitMap -> Depth));
  365.  
  366.         switch(Config . ColourMode)
  367.         {
  368.             case COLOUR_EIGHT:    for(i = 0 ; i < 8 ; i++)
  369.                             BlinkColours[i + 8] = BlinkColours[0];
  370.  
  371.                         break;
  372.  
  373.             case COLOUR_SIXTEEN:    break;
  374.  
  375.             case COLOUR_AMIGA:    BlinkColours[3] = BlinkColours[0];
  376.                         break;
  377.  
  378.             default:        BlinkColours[3] = BlinkColours[0];
  379.                         break;
  380.         }
  381.     }
  382.  
  383.     if(Config . EightyColumns)
  384.     {
  385.         ClearCursor();
  386.  
  387.         if(Config . FontScale == SCALE_HALF)
  388.             LastColumn = 131;
  389.         else
  390.             LastColumn = 79;
  391.  
  392.         if(Config . EightyColumns == 1)
  393.             LastLine = 23;
  394.         else
  395.             LastLine = 24;
  396.  
  397.         LastPixel = 80 * 8 - 1;
  398.  
  399.         BackupRender();
  400.  
  401.         SetAPen(RPort,0);
  402.  
  403.         SetWrMsk(RPort,0xFF);
  404.  
  405.         ScrollLineRectFill(RPort,0,(LastLine + 1) * 8,Window -> Width - 1,Window -> Height - 1);
  406.         ScrollLineRectFill(RPort,80 * 8,0,Window -> Width - 1,Window -> Height - 1);
  407.  
  408.         BackupRender();
  409.  
  410.         SetCursor();
  411.     }
  412.     else
  413.     {
  414.         LastLine    = (Window -> Height & ~7) / 8 - 1;
  415.  
  416.         LastColumn    = ((Window -> Width & ~7) / 8) - 1;
  417.         LastPixel    = (Window -> Width & ~7) - 1;
  418.  
  419.         if(!RegionSet)
  420.             Bottom = LastLine;
  421.     }
  422.  
  423.     if(LastLine > (Window -> Height & ~7) / 8 - 1)
  424.         LastLine = (Window -> Height & ~7) / 8 - 1;
  425.  
  426.     if(CursorY > LastLine)
  427.     {
  428.         ClearCursor();
  429.  
  430.         CursorY = LastLine;
  431.     }
  432.  
  433.     if(PrivateConfig . FontScale == SCALE_HALF && Config . FontScale != SCALE_HALF)
  434.     {
  435.         CursorX >>= 1;
  436.  
  437.         if(Config . EightyColumns)
  438.         {
  439.             LastColumn = 79;
  440.  
  441.             LastPixel = 80 * 8 - 1;
  442.         }
  443.         else
  444.         {
  445.             LastColumn = ((Window -> Width & ~7) / 8) - 1;
  446.  
  447.             LastPixel = (Window -> Width & ~7) - 1;
  448.         }
  449.     }
  450.  
  451.     if(PrivateConfig . ColourMode == Config . ColourMode && memcmp(&PrivateConfig . Colours[0],&Config . Colours[0],sizeof(UWORD) * 16))
  452.     {
  453.         switch(Config . ColourMode)
  454.         {
  455.             case COLOUR_EIGHT:    CopyMem(&Config . Colours[0],&ANSIColours[0],16 * sizeof(UWORD));
  456.                         break;
  457.  
  458.             case COLOUR_SIXTEEN:    CopyMem(&Config . Colours[0],&EGAColours[0],16 * sizeof(UWORD));
  459.                         break;
  460.  
  461.             case COLOUR_AMIGA:    CopyMem(&Config . Colours[0],&DefaultColours[0],16 * sizeof(UWORD));
  462.                         break;
  463.  
  464.             case COLOUR_MONO:    CopyMem(&Config . Colours[0],&AtomicColours[0],16 * sizeof(UWORD));
  465.                         break;
  466.         }
  467.     }
  468.  
  469.     if(Config . Emulation == EMULATION_EXTERNAL)
  470.     {
  471.         if(PrivateConfig . Emulation != EMULATION_EXTERNAL)
  472.             NewEmulation = TRUE;
  473.  
  474.         if(Stricmp(PrivateConfig . EmulationName,Config . EmulationName))
  475.             NewEmulation = TRUE;
  476.     }
  477.     else
  478.     {
  479.         if(XEmulatorBase && PrivateConfig . Emulation == EMULATION_EXTERNAL)
  480.         {
  481.             XEmulatorClearConsole(XEM_IO);
  482.  
  483.             CloseEmulator();
  484.  
  485.             Reset();
  486.         }
  487.  
  488.         OnMenu(Window,FULLMENUNUM(0,4,NOSUB));
  489.         OnMenu(Window,FULLMENUNUM(5,6,NOSUB));
  490.  
  491.         Config . RasterEnabled = TRUE;
  492.     }
  493.  
  494.     if(!ResetDisplay && NewEmulation && Config . EmulationName[0])
  495.     {
  496.         if(!OpenEmulator(Config . EmulationName))
  497.         {
  498.             Config . Emulation = EMULATION_ANSIVT100;
  499.  
  500.             if(Config . Font == FONT_IBM && IBM)
  501.                 CurrentFont = IBM;
  502.             else
  503.                 CurrentFont = Topaz;
  504.  
  505.             SetFont(RPort,CurrentFont);
  506.  
  507.             Config . RasterEnabled = TRUE;
  508.  
  509.             MyEasyRequest(Window,LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_EMULATION_LIBRARY_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),Config . EmulationName);
  510.         }
  511.         else
  512.         {
  513.             if(Config . RasterEnabled)
  514.             {
  515.                 Config . RasterEnabled = FALSE;
  516.  
  517.                 OffMenu(Window,FULLMENUNUM(0,4,NOSUB));
  518.                 OffMenu(Window,FULLMENUNUM(5,6,NOSUB));
  519.             }
  520.         }
  521.     }
  522.  
  523.     if(!ResetDisplay && PrivateConfig . RasterEnabled != Config . RasterEnabled)
  524.     {
  525.         RasterEraseScreen(2);
  526.  
  527.         if(Config . RasterEnabled)
  528.         {
  529.             OnMenu(Window,FULLMENUNUM(0,4,NOSUB));
  530.             OnMenu(Window,FULLMENUNUM(5,6,NOSUB));
  531.         }
  532.         else
  533.         {
  534.             OffMenu(Window,FULLMENUNUM(0,4,NOSUB));
  535.             OffMenu(Window,FULLMENUNUM(5,6,NOSUB));
  536.         }
  537.     }
  538.  
  539.     if((Config . DisableBlinking & ~TERMINAL_FASTER) && !ResetDisplay)
  540.         LoadRGB4(VPort,&Config . Colours[0],16);
  541.  
  542.     if(Config . Emulation != EMULATION_EXTERNAL)
  543.         SetCursor();
  544.  
  545.     SetTaskPri(ThisProcess,(LONG)Config . Priority);
  546.  
  547.     if(!ResetDisplay)
  548.     {
  549.         if(Config . OpenFastMacroPanel && !FastWindow)
  550.             OpenFastWindow();
  551.  
  552.         Blocking = FALSE;
  553.     }
  554. }
  555.  
  556.     /* PubScreenStuff():
  557.      *
  558.      *    This part handles the public screen setup stuff.
  559.      */
  560.  
  561. VOID
  562. PubScreenStuff()
  563. {
  564.         /* Are we to make our screen public? */
  565.  
  566.     if(Config . MakeScreenPublic)
  567.         PubScreenStatus(Screen,NULL);
  568.     else
  569.         PubScreenStatus(Screen,PSNF_PRIVATE);
  570.  
  571.         /* Are we to `shanghai' Workbench windows? */
  572.  
  573.     if(Config . ShanghaiWindows)
  574.     {
  575.         PublicModes |= SHANGHAI;
  576.  
  577.         SetPubScreenModes(PublicModes);
  578.  
  579.             /* Make this the default public screen. */
  580.  
  581.         SetDefaultPubScreen(TermIDString);
  582.     }
  583.     else
  584.     {
  585.         PublicModes &= ~SHANGHAI;
  586.  
  587.         if(LockPubScreen(DefaultPubScreen))
  588.         {
  589.             SetDefaultPubScreen(DefaultPubScreen);
  590.  
  591.             UnlockPubScreen(DefaultPubScreen,NULL);
  592.         }
  593.         else
  594.             SetDefaultPubScreen(NULL);
  595.  
  596.         SetPubScreenModes(PublicModes);
  597.     }
  598. }
  599.  
  600.     /* DeleteDisplay():
  601.      *
  602.      *    Free all resources associated with the terminal
  603.      *    display (tasks, interrupts, screen, window, etc.).
  604.      */
  605.  
  606. BYTE
  607. DeleteDisplay()
  608. {
  609.     if(Screen)
  610.     {
  611.         struct List        *PubScreenList;
  612.         struct PubScreenNode    *ScreenNode;
  613.  
  614.         PubScreenList = LockPubScreenList();
  615.  
  616.         for(ScreenNode = (struct PubScreenNode *)PubScreenList -> lh_Head ; ScreenNode -> psn_Node . ln_Succ ; ScreenNode = (struct PubScreenNode *)ScreenNode -> psn_Node . ln_Succ)
  617.         {
  618.             if(ScreenNode -> psn_Screen == Screen)
  619.                 break;
  620.         }
  621.  
  622.         if(ScreenNode)
  623.         {
  624.             if(ScreenNode -> psn_VisitorCount)
  625.             {
  626.                 UnlockPubScreenList();
  627.  
  628.                 return(FALSE);
  629.             }
  630.             else
  631.             {
  632.                 Forbid();
  633.  
  634.                 UnlockPubScreenList();
  635.  
  636.                 PubScreenStatus(Screen,PSNF_PRIVATE);
  637.  
  638.                 Permit();
  639.             }
  640.         }
  641.         else
  642.             UnlockPubScreenList();
  643.     }
  644.  
  645.     DeleteReview();
  646.  
  647.     if(Config . Emulation == EMULATION_EXTERNAL && XEmulatorBase)
  648.         CloseEmulator();
  649.  
  650.     if(StatusProcess)
  651.     {
  652.         SetSignal(0,SIGBREAKF_CTRL_C);
  653.  
  654.         Signal(StatusProcess,SIGBREAKF_CTRL_C);
  655.  
  656.         Wait(SIGBREAKF_CTRL_C);
  657.     }
  658.  
  659.     DeleteRaster();
  660.  
  661.     DeleteScale();
  662.  
  663.     if(ScrollLines)
  664.     {
  665.         FreeVec(ScrollLines);
  666.  
  667.         ScrollLines = NULL;
  668.     }
  669.  
  670.     if(Screen)
  671.         ScreenToBack(Screen);
  672.  
  673.     if(StatusWindow)
  674.     {
  675.         ClearMenuStrip(StatusWindow);
  676.         CloseWindowSafely(StatusWindow);
  677.  
  678.         StatusWindow = NULL;
  679.     }
  680.  
  681.     if(Window)
  682.     {
  683.         ClearMenuStrip(Window);
  684.  
  685.         ThisProcess -> pr_WindowPtr = OldWindowPtr;
  686.  
  687.         PopWindow();
  688.  
  689.         if(TermPort)
  690.             TermPort -> TopWindow = NULL;
  691.  
  692.         CloseWindow(Window);
  693.  
  694.         Window = NULL;
  695.     }
  696.  
  697.     if(FastWindow)
  698.     {
  699.         HadFastMacros = TRUE;
  700.  
  701.         CloseFastWindow();
  702.     }
  703.     else
  704.         HadFastMacros = FALSE;
  705.  
  706.     if(Menu)
  707.     {
  708.         FreeMenus(Menu);
  709.  
  710.         Menu = NULL;
  711.     }
  712.  
  713.     if(VisualInfo)
  714.     {
  715.         FreeVisualInfo(VisualInfo);
  716.  
  717.         VisualInfo = NULL;
  718.     }
  719.  
  720.     DeletePacketWindow();
  721.  
  722.     if(Screen)
  723.     {
  724.         CloseScreen(Screen);
  725.  
  726.         Screen = NULL;
  727.     }
  728.  
  729.     if(InterleavedBitMap)
  730.     {
  731.         DeleteInterleavedBitMap(InterleavedBitMap);
  732.  
  733.         InterleavedBitMap = NULL;
  734.     }
  735.  
  736.     return(TRUE);
  737. }
  738.  
  739.     /* CreateDisplay(BYTE FirstSetup):
  740.      *
  741.      *    Open the display and allocate associated data.
  742.      */
  743.  
  744. UBYTE *
  745. CreateDisplay(BYTE FirstSetup)
  746. {
  747.     UWORD             Dummy = ~0,Count = 0,i;
  748.     LONG             ErrorCode,Top,Height;
  749.     ULONG             TagArray[9];
  750.     struct MenuItem        *SomeItem;
  751.     struct Rectangle     OverscanSize;
  752.     BYTE             OpenFailed = FALSE,
  753.                  ScreenDepth;
  754.  
  755.         /* We'll configure the screen parameters at
  756.          * run time, at first we'll set up the screen
  757.          * depth.
  758.          */
  759.  
  760.     TagArray[Count++] = SA_Depth;
  761.  
  762.         /* Now set up the approriate colour mode. */
  763.  
  764.     switch(Config . ColourMode)
  765.     {
  766.         case COLOUR_EIGHT:    if(Config . DisableBlinking & ~TERMINAL_FASTER)
  767.                         TagArray[Count++] = ScreenDepth = 3;
  768.                     else
  769.                         TagArray[Count++] = ScreenDepth = 4;
  770.  
  771.                     TagArray[Count++] = SA_DetailPen;
  772.                     TagArray[Count++] = 0;
  773.  
  774.                     if(Config . DisableBlinking & TERMINAL_FASTER)
  775.                     {
  776.                         TagArray[Count++] = SA_BlockPen;
  777.                         TagArray[Count++] = 7;
  778.                     }
  779.                     else
  780.                     {
  781.                         TagArray[Count++] = SA_Pens;
  782.                         TagArray[Count++] = (LONG)&ANSIPens;
  783.  
  784.                         TagArray[Count++] = SA_BlockPen;
  785.                         TagArray[Count++] = 4;
  786.                     }
  787.  
  788.                     break;
  789.  
  790.         case COLOUR_SIXTEEN:    TagArray[Count++] = ScreenDepth = 4;
  791.  
  792.                     TagArray[Count++] = SA_DetailPen;
  793.                     TagArray[Count++] = 0;
  794.  
  795.                     if(Config . DisableBlinking & TERMINAL_FASTER)
  796.                     {
  797.                         TagArray[Count++] = SA_BlockPen;
  798.                         TagArray[Count++] = 15;
  799.                     }
  800.                     else
  801.                     {
  802.                         TagArray[Count++] = SA_Pens;
  803.                         TagArray[Count++] = (LONG)&EGAPens;
  804.  
  805.                         TagArray[Count++] = SA_BlockPen;
  806.                         TagArray[Count++] = 8;
  807.                     }
  808.  
  809.                     break;
  810.  
  811.         case COLOUR_MONO:    TagArray[Count++] = ScreenDepth = 1;
  812.  
  813.                     break;
  814.  
  815.         case COLOUR_AMIGA:    TagArray[Count++] = ScreenDepth = 2;
  816.  
  817.                     if(!(Config . DisableBlinking & TERMINAL_FASTER))
  818.                     {
  819.                         TagArray[Count++] = SA_Pens;
  820.                         TagArray[Count++] = (LONG)&Dummy;
  821.                     }
  822.  
  823.                     break;
  824.     }
  825.  
  826.         /* Terminate the tag array. */
  827.  
  828.     TagArray[Count] = TAG_END;
  829.  
  830.         /* Inquire overscan limits and try to create an interleaved
  831.          * bitmap if possible.
  832.          */
  833.  
  834.     if(Config . DisableBlinking & TERMINAL_FASTER)
  835.     {
  836.         if(QueryOverscan(Config . DisplayMode,&OverscanSize,OSCAN_TEXT))
  837.             InterleavedBitMap = CreateInterleavedBitMap(OverscanSize . MaxX - OverscanSize . MinX + 1,OverscanSize . MaxY - OverscanSize . MinY + 1,ScreenDepth);
  838.     }
  839.  
  840.         /* Open the screen with the given requirements. */
  841.  
  842. #ifdef MC68030
  843. OpenS:    SPrintf(ScreenTitle,LocaleString(MSG_TERMINIT_SCREENTITLE_30_TXT),TermName,TermDate,TermIDString);
  844. #else
  845. OpenS:    SPrintf(ScreenTitle,LocaleString(MSG_TERMINIT_SCREENTITLE_00_TXT),TermName,TermDate,TermIDString);
  846. #endif    /* MC68030 */
  847.  
  848.     if(InterleavedBitMap)
  849.     {
  850.         Screen = (struct Screen *)OpenScreenTags(NULL,
  851.             SA_Title,    ScreenTitle,
  852.             SA_DClip,    &OverscanSize,
  853.             SA_BitMap,    InterleavedBitMap,
  854.             SA_DisplayID,    Config . DisplayMode,
  855.             SA_Font,    &DefaultFont,
  856.             SA_Behind,    TRUE,
  857.             SA_AutoScroll,    TRUE,
  858.             SA_ShowTitle,    Config . TitleBar,
  859.             SA_PubName,    TermIDString,
  860.             SA_ErrorCode,    &ErrorCode,
  861.             TAG_MORE,    &TagArray[0],
  862.         TAG_END);
  863.     }
  864.     else
  865.     {
  866.         Screen = (struct Screen *)OpenScreenTags(NULL,
  867.             SA_Title,    ScreenTitle,
  868.             SA_Overscan,    OSCAN_TEXT,
  869.             SA_DisplayID,    Config . DisplayMode,
  870.             SA_Font,    &DefaultFont,
  871.             SA_Behind,    TRUE,
  872.             SA_AutoScroll,    TRUE,
  873.             SA_ShowTitle,    Config . TitleBar,
  874.             SA_PubName,    TermIDString,
  875.             SA_ErrorCode,    &ErrorCode,
  876.             TAG_MORE,    &TagArray[0],
  877.         TAG_END);
  878.     }
  879.  
  880.         /* We've got an error. */
  881.  
  882.     if(!Screen)
  883.     {
  884.         if(!OpenFailed)
  885.         {
  886.             switch(ErrorCode)
  887.             {
  888.                     /* Can't open screen with these display
  889.                      * modes.
  890.                      */
  891.  
  892.                 case OSERR_NOMONITOR:
  893.                 case OSERR_NOCHIPS:
  894.                 case OSERR_UNKNOWNMODE:        if(Config . DisplayMode & LACE)
  895.                                     Config . DisplayMode = HIRESLACE_KEY;
  896.                                 else
  897.                                     Config . DisplayMode = HIRES_KEY;
  898.  
  899.                                 OpenFailed = TRUE;
  900.  
  901.                                 goto OpenS;
  902.  
  903.                 case OSERR_PUBNOTUNIQUE:    return(LocaleString(MSG_TERMINIT_SCREEN_ID_ALREADY_IN_USE_TXT));
  904.             }
  905.         }
  906.  
  907.             /* Some different error, probably out of
  908.              * memory.
  909.              */
  910.  
  911.         return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_SCREEN_TXT));
  912.     }
  913.  
  914.         /* Set up scaling data (bitmaps & rastports). */
  915.  
  916.     if(!CreateScale())
  917.         return(LocaleString(MSG_TERMINIT_FAILED_TO_CREATE_FONT_SCALING_INFO_TXT));
  918.  
  919.         /* Obtain visual info (whatever that may be). */
  920.  
  921.     if(!(VisualInfo = GetVisualInfo(Screen,TAG_DONE)))
  922.         return(LocaleString(MSG_TERMINIT_FAILED_TO_OBTAIN_VISUAL_INFO_TXT));
  923.  
  924.     VPort = &Screen -> ViewPort;
  925.  
  926.         /* Fill the `default' colour with current values. */
  927.  
  928.     if(Initializing)
  929.     {
  930.         for(i = 0 ; i < 16 ; i++)
  931.             DefaultColours[i] = GetRGB4(VPort -> ColorMap,i);
  932.  
  933.         Initializing = FALSE;
  934.     }
  935.  
  936.         /* Load the approriate colours. */
  937.  
  938.     if(LoadColours)
  939.     {
  940.         switch(Config . ColourMode)
  941.         {
  942.             case COLOUR_EIGHT:    CopyMem(&ANSIColours[0],&Config . Colours[0],16 * sizeof(UWORD));
  943.                         break;
  944.  
  945.             case COLOUR_SIXTEEN:    CopyMem(&EGAColours[0],&Config . Colours[0],16 * sizeof(UWORD));
  946.                         break;
  947.  
  948.             case COLOUR_AMIGA:    CopyMem(&DefaultColours[0],&Config . Colours[0],16 * sizeof(UWORD));
  949.                         break;
  950.  
  951.             case COLOUR_MONO:    CopyMem(&AtomicColours[0],&Config . Colours[0],16 * sizeof(UWORD));
  952.                         break;
  953.         }
  954.  
  955.         LoadColours = FALSE;
  956.     }
  957.  
  958.         /* Reset the current colours and the blinking equivalents. */
  959.  
  960.     for(i = 0 ; i < 16 ; i++)
  961.         BlinkColours[i] = Config . Colours[i];
  962.  
  963.     LoadRGB4(VPort,&Config . Colours[0],(1 << Screen -> RastPort . BitMap -> Depth));
  964.  
  965.         /* Fiddle with the blinking colours. */
  966.  
  967.     switch(Config . ColourMode)
  968.     {
  969.         case COLOUR_EIGHT:    for(i = 0 ; i < 8 ; i++)
  970.                         BlinkColours[i + 8] = BlinkColours[0];
  971.  
  972.                     break;
  973.  
  974.         case COLOUR_SIXTEEN:    break;
  975.  
  976.         case COLOUR_AMIGA:
  977.         default:        BlinkColours[3] = BlinkColours[0];
  978.                     break;
  979.     }
  980.  
  981.     if(Config . TitleBar)
  982.     {
  983.         Top = Screen -> BarHeight + 2;
  984.  
  985.         if(Config . StatusLine)
  986.         {
  987.             if(Config . StatusLine == STATUSLINE_COMPRESSED)
  988.                 Height = Screen -> Height - (Screen -> BarHeight + 2) - 10;
  989.             else
  990.                 Height = Screen -> Height - (Screen -> BarHeight + 2) - 27;
  991.         }
  992.         else
  993.             Height = Screen -> Height - (Screen -> BarHeight + 2);
  994.     }
  995.     else
  996.     {
  997.         Top = 0;
  998.  
  999.         if(Config . StatusLine)
  1000.         {
  1001.             if(Config . StatusLine == STATUSLINE_COMPRESSED)
  1002.                 Height = Screen -> Height - 10;
  1003.             else
  1004.                 Height = Screen -> Height - 27;
  1005.         }
  1006.         else
  1007.             Height = Screen -> Height;
  1008.     }
  1009.  
  1010.         /* Open the main window. */
  1011.  
  1012.     if(!(Window = OpenWindowTags(NULL,
  1013.         WA_Top,        Top,
  1014.         WA_Left,    0,
  1015.         WA_Width,    Screen -> Width,
  1016.         WA_Height,    Height,
  1017.         WA_Backdrop,    TRUE,
  1018.         WA_Borderless,    TRUE,
  1019.         WA_SmartRefresh,TRUE,
  1020.         WA_CustomScreen,Screen,
  1021.         WA_RMBTrap,    TRUE,
  1022.         WA_IDCMP,    IDCMP_RAWKEY | IDCMP_MOUSEMOVE | IDCMP_GADGETUP | IDCMP_MENUPICK | IDCMP_MOUSEMOVE | IDCMP_MOUSEBUTTONS | IDCMP_CLOSEWINDOW | IDCMP_NEWSIZE | IDCMP_INACTIVEWINDOW | LISTVIEWIDCMP,
  1023.     TAG_DONE)))
  1024.         return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_WINDOW_TXT));
  1025.  
  1026.         /* Push it on the window stack (should become bottommost
  1027.          * entry).
  1028.          */
  1029.  
  1030.     PushWindow(Window);
  1031.  
  1032.     if(TermPort)
  1033.         TermPort -> TopWindow = Window;
  1034.  
  1035.         /* Open the tiny status window. */
  1036.  
  1037.     if(Config . StatusLine)
  1038.     {
  1039.         if(!(StatusWindow = OpenWindowTags(NULL,
  1040.             WA_Top,        Window -> TopEdge + Window -> Height,
  1041.             WA_Left,    0,
  1042.             WA_Width,    Screen -> Width,
  1043.             WA_Height,    Screen -> Height - (Window -> TopEdge + Window -> Height),
  1044.             WA_Backdrop,    TRUE,
  1045.             WA_Borderless,    TRUE,
  1046.             WA_SmartRefresh,TRUE,
  1047.             WA_CustomScreen,Screen,
  1048.             WA_RMBTrap,    TRUE,
  1049.         TAG_DONE)))
  1050.             return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_STATUS_WINDOW_TXT));
  1051.     }
  1052.     else
  1053.         StatusWindow = NULL;
  1054.  
  1055.         /* Default console setup. */
  1056.  
  1057.     if(Config . EightyColumns)
  1058.     {
  1059.         LastColumn = 79;
  1060.  
  1061.         if(Config . EightyColumns == 1)
  1062.             LastLine = 23;
  1063.         else
  1064.             LastLine = 24;
  1065.  
  1066.         LastPixel = 80 * 8 - 1;
  1067.     }
  1068.     else
  1069.     {
  1070.         LastLine    = (Window -> Height & ~7) / 8 - 1;
  1071.         LastColumn    = ((Window -> Width & ~7) / 8) - 1;
  1072.         LastPixel    = (Window -> Width & ~7) - 1;
  1073.     }
  1074.  
  1075.     if(LastLine > (Window -> Height & ~7) / 8 - 1)
  1076.         LastLine = (Window -> Height & ~7) / 8 - 1;
  1077.  
  1078.     CursorX = 0;
  1079.     CursorY    = 0;
  1080.  
  1081.     SetDrMd(Window -> RPort,JAM2);
  1082.  
  1083.     if(StatusWindow)
  1084.     {
  1085.         StatusWindow -> UserPort = Window -> UserPort;
  1086.  
  1087.         ModifyIDCMP(StatusWindow,Window -> IDCMPFlags);
  1088.     }
  1089.  
  1090.     RPort = Window -> RPort;
  1091.  
  1092.         /* Redirect AmigaDOS requesters. */
  1093.  
  1094.     OldWindowPtr = ThisProcess -> pr_WindowPtr;
  1095.  
  1096.     ThisProcess -> pr_WindowPtr = (APTR)Window;
  1097.  
  1098.         /* Create the character raster. */
  1099.  
  1100.     if(!CreateRaster())
  1101.         return(LocaleString(MSG_TERMINIT_UNABLE_TO_CREATE_SCREEN_RASTER_TXT));
  1102.  
  1103.         /* Set up the scrolling info. */
  1104.  
  1105.     ScrollLineCount = Window -> Height >> 3;
  1106.  
  1107.     if(!(ScrollLines = (struct ScrollLine *)AllocVec(sizeof(struct ScrollLineInfo) * ScrollLineCount,MEMF_ANY|MEMF_CLEAR)))
  1108.         return(LocaleString(MSG_TERMINIT_FAILED_TO_CREATE_SCROLLING_SUPPORT_INFO_TXT));
  1109.  
  1110.     ScrollLineEraseScreen(2);
  1111.  
  1112.         /* Reset terminal emulation. */
  1113.  
  1114.     if(Config . Emulation != EMULATION_EXTERNAL) 
  1115.         Reset();
  1116.     else
  1117.     {
  1118.         if(XEmulatorBase)
  1119.             XEmulatorResetConsole(XEM_IO);
  1120.     }
  1121.  
  1122.         /* Set the font. */
  1123.  
  1124.     if(Config . Font == FONT_IBM && IBM)
  1125.         CurrentFont = IBM;
  1126.     else
  1127.         CurrentFont = Topaz;
  1128.  
  1129.     SetFont(RPort,CurrentFont);
  1130.  
  1131.         /* Create the menu strip. */
  1132.  
  1133.     if(!(Menu = CreateMenus(TermMenu,
  1134.         GTMN_FrontPen, 0,
  1135.     TAG_DONE)))
  1136.         return(LocaleString(MSG_TERMINIT_FAILED_TO_CREATE_MENUS_TXT));
  1137.  
  1138.         /* Do the menu layout. */
  1139.  
  1140.     if(!LayoutMenus(Menu,VisualInfo,
  1141.         GTMN_TextAttr,&DefaultFont,
  1142.     TAG_DONE))
  1143.         return(LocaleString(MSG_TERMINIT_FAILED_TO_LAYOUT_MENUS_TXT));
  1144.  
  1145.         /* Disable the `Execute ARexx Command' menu item if
  1146.          * the rexx server is not available.
  1147.          */
  1148.  
  1149.     if(!RexxSysBase)
  1150.     {
  1151.         struct MenuItem *SomeItem;
  1152.  
  1153.         if(SomeItem = FindThisItem(MEN_REXXCOMMAND))
  1154.             SomeItem -> Flags &= ~ITEMENABLED;
  1155.     }
  1156.  
  1157.         /* Add a tick if file capture is active. */
  1158.  
  1159.     if(FileCapture)
  1160.     {
  1161.         if(SomeItem = FindThisItem(MEN_CAPTUREDISK))
  1162.             SomeItem -> Flags |= CHECKED;
  1163.     }
  1164.  
  1165.         /* Add a tick if printer capture is active. */
  1166.  
  1167.     if(PrinterCapture)
  1168.     {
  1169.         if(SomeItem = FindThisItem(MEN_CAPTUREPRINTER))
  1170.             SomeItem -> Flags |= CHECKED;
  1171.     }
  1172.  
  1173.         /* Add a tick if the buffer is frozen. */
  1174.  
  1175.     if(BufferFrozen)
  1176.     {
  1177.         if(SomeItem = FindThisItem(MEN_FREEZEBUFFER))
  1178.             SomeItem -> Flags |= CHECKED;
  1179.     }
  1180.  
  1181.         /* Add the menu to the windows. */
  1182.  
  1183.     SetMenuStrip(Window,Menu);
  1184.  
  1185.         /* Disable the `Print Screen' and `Save ASCII' functions
  1186.          * if raster is not enabled.
  1187.          */
  1188.  
  1189.     if(!Config . RasterEnabled)
  1190.     {
  1191.         OffMenu(Window,FULLMENUNUM(0,4,NOSUB));
  1192.         OffMenu(Window,FULLMENUNUM(5,6,NOSUB));
  1193.     }
  1194.  
  1195.         /* Enable the menu. */
  1196.  
  1197.     Window -> Flags &= ~WFLG_RMBTRAP;
  1198.  
  1199.     if(StatusWindow)
  1200.     {
  1201.         BYTE Pen;
  1202.  
  1203.         SetMenuStrip(StatusWindow,Menu);
  1204.  
  1205.         StatusWindow -> Flags &= ~WFLG_RMBTRAP;
  1206.  
  1207.             /* Render the information. */
  1208.  
  1209.         switch(Config . ColourMode)
  1210.         {
  1211.             case COLOUR_EIGHT:    Pen = 7;
  1212.                         break;
  1213.  
  1214.             case COLOUR_SIXTEEN:    Pen = 15;
  1215.                         break;
  1216.  
  1217.             default:        Pen = 1;
  1218.                         break;
  1219.         }
  1220.  
  1221.         SetDrMd(StatusWindow -> RPort,JAM2);
  1222.  
  1223.         if(Config . StatusLine == STATUSLINE_COMPRESSED)
  1224.         {
  1225.             StatusOffset = (Screen -> Width - (73 * 8)) / 2;
  1226.  
  1227.             SetRast(StatusWindow -> RPort,Pen);
  1228.  
  1229.             SetAPen(StatusWindow -> RPort,0);
  1230.             SetBPen(StatusWindow -> RPort,Pen);
  1231.         }
  1232.         else
  1233.         {
  1234.             SetAPen(StatusWindow -> RPort,Pen);
  1235.             SetBPen(StatusWindow -> RPort,0);
  1236.  
  1237.                 /* Draw a separating line. */
  1238.  
  1239.             Move(StatusWindow -> RPort,0,0);
  1240.             Draw(StatusWindow -> RPort,StatusWindow -> Width - 1,0);
  1241.  
  1242.             StatusOffset = (Screen -> Width - (72 * 8)) / 2;
  1243.  
  1244.             Move(StatusWindow -> RPort,StatusOffset,10);
  1245.             Text(StatusWindow -> RPort,LocaleString(MSG_TERMINIT_STATUSLINE_1_TXT),63);
  1246.  
  1247.             Move(StatusWindow -> RPort,StatusOffset,23);
  1248.             Text(StatusWindow -> RPort,LocaleString(MSG_TERMINIT_STATUS_LINE_2_TXT),63);
  1249.  
  1250.             DrawBevelBox(StatusWindow -> RPort,StatusOffset + 53,2,72,12,
  1251.                 GTBB_Recessed,    TRUE,
  1252.                 GT_VisualInfo,    VisualInfo,
  1253.             TAG_DONE);
  1254.  
  1255.             DrawBevelBox(StatusWindow -> RPort,StatusOffset + 53,15,72,12,
  1256.                 GTBB_Recessed,    TRUE,
  1257.                 GT_VisualInfo,    VisualInfo,
  1258.             TAG_DONE);
  1259.  
  1260.             DrawBevelBox(StatusWindow -> RPort,StatusOffset + 197,2,88,12,
  1261.                 GTBB_Recessed,    TRUE,
  1262.                 GT_VisualInfo,    VisualInfo,
  1263.             TAG_DONE);
  1264.  
  1265.             DrawBevelBox(StatusWindow -> RPort,StatusOffset + 197,15,88,12,
  1266.                 GTBB_Recessed,    TRUE,
  1267.                 GT_VisualInfo,    VisualInfo,
  1268.             TAG_DONE);
  1269.  
  1270.             DrawBevelBox(StatusWindow -> RPort,StatusOffset + 372,2,80,12,
  1271.                 GTBB_Recessed,    TRUE,
  1272.                 GT_VisualInfo,    VisualInfo,
  1273.             TAG_DONE);
  1274.  
  1275.             DrawBevelBox(StatusWindow -> RPort,StatusOffset + 372,15,80,12,
  1276.                 GTBB_Recessed,    TRUE,
  1277.                 GT_VisualInfo,    VisualInfo,
  1278.             TAG_DONE);
  1279.  
  1280.             DrawBevelBox(StatusWindow -> RPort,StatusOffset + 508,2,72,12,
  1281.                 GTBB_Recessed,    TRUE,
  1282.                 GT_VisualInfo,    VisualInfo,
  1283.             TAG_DONE);
  1284.  
  1285.             DrawBevelBox(StatusWindow -> RPort,StatusOffset + 508,15,72,12,
  1286.                 GTBB_Recessed,    TRUE,
  1287.                 GT_VisualInfo,    VisualInfo,
  1288.             TAG_DONE);
  1289.         }
  1290.     }
  1291.  
  1292.     strcpy(EmulationName,LocaleString(MSG_TERMXEM_NO_EMULATION_TXT));
  1293.  
  1294.         /* Create the status server. */
  1295.  
  1296.     StatusProcess = CreateNewProcTags(
  1297.         NP_Entry,    StatusServer,
  1298.         NP_Name,    "term status process",
  1299.         NP_WindowPtr,    -1,
  1300.         NP_Priority,    5,
  1301.     TAG_DONE);
  1302.  
  1303.         /* Wait for ringback signal. */
  1304.  
  1305.     Wait(SIGBREAKF_CTRL_C);
  1306.  
  1307.         /* Status server has `died'. */
  1308.  
  1309.     if(!StatusProcess)
  1310.         return(LocaleString(MSG_TERMINIT_UNABLE_TO_CREATE_STATUS_TASK_TXT));
  1311.  
  1312.         /* Restart the fast! macro panel. */
  1313.  
  1314.     if(HadFastMacros || Config . OpenFastMacroPanel)
  1315.         OpenFastWindow();
  1316.  
  1317.         /* Obtain the default public screen name just in case
  1318.          * we'll need it later.
  1319.          */
  1320.  
  1321.     GetDefaultPubScreen(DefaultPubScreen);
  1322.  
  1323.     if(Config . Emulation == EMULATION_EXTERNAL && Config . EmulationName[0])
  1324.     {
  1325.         if(!OpenEmulator(Config . EmulationName))
  1326.         {
  1327.             Config . Emulation = EMULATION_ANSIVT100;
  1328.  
  1329.             if(Config . Font == FONT_IBM && IBM)
  1330.                 CurrentFont = IBM;
  1331.             else
  1332.                 CurrentFont = Topaz;
  1333.  
  1334.             SetFont(RPort,CurrentFont);
  1335.  
  1336.             Config . RasterEnabled = TRUE;
  1337.  
  1338.             MyEasyRequest(Window,LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_EMULATION_LIBRARY_TXT),Config . EmulationName);
  1339.         }
  1340.         else
  1341.         {
  1342.             if(Config . RasterEnabled)
  1343.             {
  1344.                 Config . RasterEnabled = FALSE;
  1345.  
  1346.                 RasterEraseScreen(2);
  1347.  
  1348.                 EraseScreen("2");
  1349.  
  1350.                 OffMenu(Window,FULLMENUNUM(0,4,NOSUB));
  1351.                 OffMenu(Window,FULLMENUNUM(5,6,NOSUB));
  1352.             }
  1353.         }
  1354.     }
  1355.  
  1356.     return(NULL);
  1357. }
  1358.  
  1359.     /* CloseAll():
  1360.      *
  1361.      *    Free all resources and leave the program.
  1362.      */
  1363.  
  1364. VOID
  1365. CloseAll()
  1366. {
  1367.     FreeDialList();
  1368.  
  1369.     if(StripBuffer)
  1370.         FreeVec(StripBuffer);
  1371.  
  1372.     if(BackupConfig)
  1373.         FreeVec(BackupConfig);
  1374.  
  1375.     if(IntuitionBase && Window)
  1376.         BlockWindows();
  1377.  
  1378.     if(RexxProcess)
  1379.     {
  1380.         Signal(RexxProcess,SIGBREAKF_CTRL_C);
  1381.  
  1382.         Wait(SIGBREAKF_CTRL_C);
  1383.     }
  1384.  
  1385.     if(ClipProcess)
  1386.     {
  1387.         Signal(ClipProcess,SIGBREAKF_CTRL_C);
  1388.  
  1389.         Wait(SIGBREAKF_CTRL_C);
  1390.     }
  1391.  
  1392.     if(TermRexxPort)
  1393.     {
  1394.         if(RexxSysBase)
  1395.         {
  1396.             struct RexxMsg *RexxMsg;
  1397.  
  1398.             while(RexxMsg = (struct RexxMsg *)GetMsg(TermRexxPort))
  1399.                 ReplyRexxCommand(RexxMsg,RC_ERROR,0,NULL);
  1400.         }
  1401.  
  1402.         DeleteMsgPort(TermRexxPort);
  1403.     }
  1404.  
  1405.     if(XprIO && XProtocolBase)
  1406.         XProtocolCleanup(XprIO);
  1407.  
  1408.     if(XProtocolBase)
  1409.         CloseLibrary(XProtocolBase);
  1410.  
  1411.     if(XprIO)
  1412.         FreeVec(XprIO);
  1413.  
  1414.     if(FileAnchor)
  1415.         FreeVec(FileAnchor);
  1416.  
  1417.     if(Phonebook && PhoneSize)
  1418.         DeletePhonebook(Phonebook,PhoneSize,TRUE);
  1419.  
  1420.     if(MacroKeys)
  1421.         FreeVec(MacroKeys);
  1422.  
  1423.     ClearBuffer();
  1424.  
  1425.     DeleteSpeech();
  1426.  
  1427.     Forbid();
  1428.  
  1429.     BufferClosed = TRUE;
  1430.  
  1431.     if(BufferLines)
  1432.         FreeVec(BufferLines);
  1433.  
  1434.     if(BufferSemaphore)
  1435.         FreeVec(BufferSemaphore);
  1436.  
  1437.     Permit();
  1438.  
  1439.     ClearDownloadObjects();
  1440.  
  1441.     if(DownloadSemaphore)
  1442.         FreeVec(DownloadSemaphore);
  1443.  
  1444.     if(AttentionBuffers[0])
  1445.         FreeVec(AttentionBuffers[0]);
  1446.  
  1447.     FreeDialList();
  1448.  
  1449.     ClearFastMacroList(&FastMacroList);
  1450.  
  1451.     if(FileCapture)
  1452.     {
  1453.         BufferClose(FileCapture);
  1454.  
  1455.         if(!GetFileSize(CaptureName))
  1456.             DeleteFile(CaptureName);
  1457.         else
  1458.             SetProtection(CaptureName,FIBF_EXECUTE);
  1459.     }
  1460.  
  1461.     if(PrinterCapture)
  1462.         Close(PrinterCapture);
  1463.  
  1464.     CloseEmulator();
  1465.  
  1466.     if(XEM_MacroKeys)
  1467.         FreeVec(XEM_MacroKeys);
  1468.  
  1469.     DeleteDisplay();
  1470.  
  1471.     if(KeySegment)
  1472.         UnLoadSeg(KeySegment);
  1473.  
  1474.     if(TimeRequest)
  1475.     {
  1476.         if(TimeRequest -> tr_node . io_Device)
  1477.             CloseDevice(TimeRequest);
  1478.  
  1479.         DeleteIORequest(TimeRequest);
  1480.     }
  1481.  
  1482.     if(TimePort)
  1483.         DeleteMsgPort(TimePort);
  1484.  
  1485.     DeleteBeep();
  1486.  
  1487.     ClearSerial();
  1488.  
  1489.     DeleteSerial();
  1490.  
  1491.     ShutdownCx();
  1492.  
  1493.     if(TermPort)
  1494.     {
  1495.         if(TermID != -1)
  1496.         {
  1497.             ObtainSemaphore(&TermPort -> OpenSemaphore);
  1498.  
  1499.             TermPort -> OpenCount--;
  1500.  
  1501.             if(TermPort -> OpenCount <= 0 && !TermPort -> HoldIt)
  1502.             {
  1503.                 RemPort(&TermPort -> ExecNode);
  1504.  
  1505.                 ReleaseSemaphore(&TermPort -> OpenSemaphore);
  1506.  
  1507.                 FreeVec(TermPort);
  1508.             }
  1509.             else
  1510.                 ReleaseSemaphore(&TermPort -> OpenSemaphore);
  1511.         }
  1512.     }
  1513.  
  1514.     if(RequesterList)
  1515.         FreeVec(RequesterList);
  1516.  
  1517.     if(OwnDevUnitBase)
  1518.         CloseLibrary(OwnDevUnitBase);
  1519.  
  1520.     if(LayersBase)
  1521.         CloseLibrary(LayersBase);
  1522.  
  1523.     if(CxBase)
  1524.         CloseLibrary(CxBase);
  1525.  
  1526.     if(IFFParseBase)
  1527.         CloseLibrary(IFFParseBase);
  1528.  
  1529.     if(AslBase)
  1530.         CloseLibrary(AslBase);
  1531.  
  1532.     if(DiskfontBase)
  1533.         CloseLibrary(DiskfontBase);
  1534.  
  1535.     if(FakeInputEvent)
  1536.         FreeVec(FakeInputEvent);
  1537.  
  1538.     if(ConsoleDevice)
  1539.         CloseDevice(ConsoleRequest);
  1540.  
  1541.     if(ConsoleRequest)
  1542.         FreeVec(ConsoleRequest);
  1543.  
  1544.     if(IBM)
  1545.         CloseFont(IBM);
  1546.  
  1547.     if(GFX)
  1548.         CloseFont(GFX);
  1549.  
  1550.     if(Topaz)
  1551.         CloseFont(Topaz);
  1552.  
  1553.     if(RexxSysBase)
  1554.         CloseLibrary(RexxSysBase);
  1555.  
  1556.     if(GadToolsBase)
  1557.         CloseLibrary(GadToolsBase);
  1558.  
  1559.     if(UtilityBase)
  1560.         CloseLibrary(UtilityBase);
  1561.  
  1562.     if(GfxBase)
  1563.         CloseLibrary(GfxBase);
  1564.  
  1565.     if(IntuitionBase)
  1566.         CloseLibrary(IntuitionBase);
  1567.  
  1568.     LocaleClose();
  1569.  
  1570.     if(WBenchMsg)
  1571.     {
  1572.         if(DOSBase)
  1573.             CloseLibrary(DOSBase);
  1574.  
  1575.         Forbid();
  1576.  
  1577.         ReplyMsg((struct Message *)WBenchMsg);
  1578.     }
  1579. }
  1580.  
  1581.     /* OpenAll():
  1582.      *
  1583.      *    Open all required resources or return an error message
  1584.      *    if anything went wrong.
  1585.      */
  1586.  
  1587. UBYTE *
  1588. OpenAll(STRPTR ConfigPath)
  1589. {
  1590.     UBYTE     PathBuffer[256];
  1591.     WORD     i;
  1592.     UBYTE    *Result,
  1593.         *Error;
  1594.  
  1595.     LocaleOpen("term.catalog","english",4);
  1596.  
  1597.     LocalizeMenu(TermMenu,MSG_TERMDATA_PROJECT_MEN);
  1598.  
  1599.     if(!(IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",0)))
  1600.         return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_INTUITION_LIBRARY_TXT));
  1601.  
  1602.     if((SysBase -> SoftVer < 175 && SysBase -> LibNode . lib_Version == 37) || SysBase -> LibNode . lib_Version < 37)
  1603.     {
  1604.         if(!MyEasyRequest(NULL,LocaleString(MSG_TERMINIT_VERSION_WARNING_TXT),
  1605.             LocaleString(MSG_TERMINIT_PROCEED_BACK_OUT_TXT),SysBase -> LibNode . lib_Version,SysBase -> SoftVer))
  1606.                 return("");
  1607.     }
  1608.  
  1609.     PublicModes = SetPubScreenModes(0);
  1610.  
  1611.     SetPubScreenModes(PublicModes);
  1612.  
  1613.     if(!(GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",0)))
  1614.         return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_GRAPHICS_LIBRARY_TXT));
  1615.  
  1616.     if(!(UtilityBase = OpenLibrary("utility.library",0)))
  1617.         return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_UTILITY_LIBRARY_TXT));
  1618.  
  1619.     LanguageCheck();
  1620.  
  1621.     if(!(GadToolsBase = OpenLibrary("gadtools.library",0)))
  1622.         return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_GADTOOLS_LIBRARY_TXT));
  1623.  
  1624.     if(!(AslBase = OpenLibrary("asl.library",0)))
  1625.         return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_ASL_LIBRARY_TXT));
  1626.  
  1627.     if(!(IFFParseBase = OpenLibrary("iffparse.library",0)))
  1628.         return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_IFFPARSE_LIBRARY_TXT));
  1629.  
  1630.     if(!(CxBase = OpenLibrary("commodities.library",0)))
  1631.         return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_COMMODITIES_LIBRARY_TXT));
  1632.  
  1633.     if(!(LayersBase = OpenLibrary("layers.library",0)))
  1634.         return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_LAYERS_LIBRARY_TXT));
  1635.  
  1636.     OwnDevUnitBase = OpenLibrary(ODU_NAME,0);
  1637.  
  1638.     if(!(Topaz = (struct TextFont *)OpenFont(&DefaultFont)))
  1639.         return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_DEFAULT_FONT_TXT));
  1640.  
  1641.     if(!(ConsoleRequest = (struct IOStdReq *)AllocVec(sizeof(struct IOStdReq),MEMF_ANY|MEMF_CLEAR)))
  1642.         return(LocaleString(MSG_TERMINIT_FAILED_TO_ALLOCATE_CONSOLE_REQUEST_TXT));
  1643.  
  1644.     if(OpenDevice("console.device",CONU_LIBRARY,ConsoleRequest,0))
  1645.         return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_CONSOLE_DEVICE_TXT));
  1646.  
  1647.     ConsoleDevice = &ConsoleRequest -> io_Device -> dd_Library;
  1648.  
  1649.     if(!(FakeInputEvent = (struct InputEvent *)AllocVec(sizeof(struct InputEvent),MEMF_ANY|MEMF_CLEAR)))
  1650.         return(LocaleString(MSG_TERMINIT_FAILED_TO_ALLOCATE_INPUTEVENT_TXT));
  1651.  
  1652.     FakeInputEvent -> ie_Class = IECLASS_RAWKEY;
  1653.  
  1654.     if(!(MacroKeys = (struct MacroKeys *)AllocVec(sizeof(struct MacroKeys),MEMF_ANY|MEMF_CLEAR)))
  1655.         return(LocaleString(MSG_TERMINIT_FAILED_TO_ALLOCATE_MACROKEYS_TXT));
  1656.  
  1657.     if(!(RequesterList = (struct Requester *)AllocVec(10 * sizeof(struct Requester),MEMF_ANY|MEMF_CLEAR)))
  1658.         return(LocaleString(MSG_TERMINIT_FAILED_TO_ALLOCATE_REQUESTER_DATA_TXT));
  1659.  
  1660.     if(DiskfontBase = (struct Library *)OpenLibrary("diskfont.library",0))
  1661.     {
  1662.         if(!(IBM = (struct TextFont *)OpenFont(&IBMFont)))
  1663.             IBM = (struct TextFont *)OpenDiskFont(&IBMFont);
  1664.  
  1665.         if(!(GFX = (struct TextFont *)OpenFont(&GFXFont)))
  1666.             GFX = (struct TextFont *)OpenDiskFont(&GFXFont);
  1667.     }
  1668.  
  1669.         /* Set up the attention buffers. */
  1670.  
  1671.     if(!(AttentionBuffers[0] = (UBYTE *)AllocVec(8 * 81,MEMF_PUBLIC|MEMF_CLEAR)))
  1672.         return(LocaleString(MSG_TERMINIT_FAILED_TO_CREATE_SEQUENCE_ATTENTION_INFO_TXT));
  1673.  
  1674.     for(i = 1 ; i < 8 ; i++)
  1675.         AttentionBuffers[i] = &AttentionBuffers[i - 1][81];
  1676.  
  1677.         /* Obtain the default environment storage
  1678.          * path.
  1679.          */
  1680.  
  1681.     if(!ConfigPath)
  1682.     {
  1683.         ConfigPath = PathBuffer;
  1684.  
  1685.         if(!GetEnvDOS("TERMPATH",PathBuffer))
  1686.         {
  1687.             APTR LastPtr = ThisProcess -> pr_WindowPtr;
  1688.             BPTR FileLock;
  1689.  
  1690.             strcpy(PathBuffer,"TERM:config");
  1691.  
  1692.             SetEnvDOS("TERMPATH",PathBuffer);
  1693.  
  1694.             ThisProcess -> pr_WindowPtr = (APTR)-1;
  1695.  
  1696.             if(FileLock = Lock("TERM:",ACCESS_READ))
  1697.                 UnLock(FileLock);
  1698.             else
  1699.             {
  1700.                 FileLock = DupLock(ThisProcess-> pr_CurrentDir);
  1701.  
  1702.                     /* Create TERM: assignment referring to
  1703.                      * current directory.
  1704.                      */
  1705.  
  1706.                 if(!AssignLock("TERM",FileLock))
  1707.                     UnLock(FileLock);
  1708.             }
  1709.  
  1710.             if(!(FileLock = Lock(PathBuffer,ACCESS_READ)))
  1711.                 FileLock = CreateDir(PathBuffer);
  1712.  
  1713.             if(FileLock)
  1714.                 UnLock(FileLock);
  1715.  
  1716.             ThisProcess -> pr_WindowPtr = LastPtr;
  1717.         }
  1718.     }
  1719.  
  1720.         /* Check for proper assignment path if necessary. */
  1721.  
  1722.         if(!Strnicmp(ConfigPath,"TERM:",5))
  1723.         {
  1724.             APTR OldPtr = ThisProcess -> pr_WindowPtr;
  1725.             BPTR DirLock;
  1726.  
  1727.             /* Block dos requesters. */
  1728.  
  1729.             ThisProcess -> pr_WindowPtr = (APTR)-1;
  1730.  
  1731.             /* Try to get a lock on `TERM:' assignment. */
  1732.  
  1733.         if(DirLock = Lock("TERM:",ACCESS_READ))
  1734.             UnLock(DirLock);
  1735.         else
  1736.         {
  1737.                 /* Clone current directory lock. */
  1738.  
  1739.             DirLock = DupLock(ThisProcess-> pr_CurrentDir);
  1740.  
  1741.                 /* Create TERM: assignment referring to
  1742.                  * current directory.
  1743.                  */
  1744.  
  1745.             if(!AssignLock("TERM",DirLock))
  1746.                 UnLock(DirLock);
  1747.         }
  1748.  
  1749.         ThisProcess -> pr_WindowPtr = OldPtr;
  1750.         }
  1751.  
  1752.         /* Create proper path names. */
  1753.  
  1754.     strcpy(LastConfig,ConfigPath);
  1755.  
  1756.     AddPart(LastConfig,"term_preferences.iff",256);
  1757.  
  1758.     if(!GetFileSize(LastConfig))
  1759.     {
  1760.         strcpy(LastConfig,ConfigPath);
  1761.  
  1762.         AddPart(LastConfig,"term.prefs",256);
  1763.     }
  1764.  
  1765.     strcpy(DefaultPubScreen,"Workbench");
  1766.  
  1767.         /* Read some more environment variables. */
  1768.  
  1769.     if(!GetEnvDOS("TERMWINDOW",WindowName))
  1770.         strcpy(WindowName,"CON:0/11//100/term Output Window/CLOSE/SCREEN TERM");
  1771.  
  1772.     GetEnvDOS("EDITOR",Config . Editor);
  1773.  
  1774.     SetPrefToDefaults(&Config,ConfigPath);
  1775.  
  1776.         /* Look for the default configuration file. */
  1777.  
  1778.     if(!ReadIFFData(LastConfig,&Config,sizeof(struct Configuration),'PREF'))
  1779.     {
  1780.         SetPrefToDefaults(&Config,ConfigPath);
  1781.  
  1782.         Initializing = TRUE;
  1783.  
  1784.         LoadColours = TRUE;
  1785.     }
  1786.     else
  1787.     {
  1788.         switch(Config . ColourMode)
  1789.         {
  1790.             case COLOUR_EIGHT:    CopyMem(&Config . Colours[0],&ANSIColours[0],16 * sizeof(UWORD));
  1791.                         break;
  1792.  
  1793.             case COLOUR_SIXTEEN:    CopyMem(&Config . Colours[0],&EGAColours[0],16 * sizeof(UWORD));
  1794.                         break;
  1795.  
  1796.             case COLOUR_AMIGA:    CopyMem(&Config . Colours[0],&DefaultColours[0],16 * sizeof(UWORD));
  1797.                         break;
  1798.  
  1799.             case COLOUR_MONO:    CopyMem(&Config . Colours[0],&AtomicColours[0],16 * sizeof(UWORD));
  1800.                         break;
  1801.         }
  1802.  
  1803.         if(Config . ColourMode == COLOUR_AMIGA)
  1804.             Initializing = FALSE;
  1805.         else
  1806.             Initializing = TRUE;
  1807.     }
  1808.  
  1809.     if(Config . OpenFastMacroPanel)
  1810.         HadFastMacros = TRUE;
  1811.  
  1812.     NewList(&FastMacroList);
  1813.  
  1814.     strcpy(LastPhone,    Config . DefaultStorage);
  1815.     AddPart(LastPhone,    "term_phonebook.iff",256);
  1816.  
  1817.     if(!GetFileSize(LastPhone))
  1818.     {
  1819.         strcpy(LastPhone,    Config . DefaultStorage);
  1820.         AddPart(LastPhone,    "phonebook.prefs",256);
  1821.     }
  1822.  
  1823.     strcpy(LastKeys,    Config . DefaultStorage);
  1824.     AddPart(LastKeys,    "term_hotkeys.iff",256);
  1825.  
  1826.     if(!GetFileSize(LastKeys))
  1827.     {
  1828.         strcpy(LastKeys,    Config . DefaultStorage);
  1829.         AddPart(LastKeys,    "hotkeys.prefs",256);
  1830.     }
  1831.  
  1832.     strcpy(LastSpeech,    Config . DefaultStorage);
  1833.     AddPart(LastSpeech,    "term_speech.iff",256);
  1834.  
  1835.     if(!GetFileSize(LastSpeech))
  1836.     {
  1837.         strcpy(LastSpeech,    Config . DefaultStorage);
  1838.         AddPart(LastSpeech,    "speech.prefs",256);
  1839.     }
  1840.  
  1841.     strcpy(LastFastMacros,    Config . DefaultStorage);
  1842.     AddPart(LastFastMacros,    "term_fastmacros.iff",256);
  1843.  
  1844.     if(!GetFileSize(LastFastMacros))
  1845.     {
  1846.         strcpy(LastFastMacros,    Config . DefaultStorage);
  1847.         AddPart(LastFastMacros,    "fastmacros.prefs",256);
  1848.     }
  1849.  
  1850.     strcpy(LastMacros,Config . MacroFile);
  1851.  
  1852.         /* Load the keyboard macros. */
  1853.  
  1854.     if(!LoadMacros(LastMacros,MacroKeys))
  1855.     {
  1856.         for(i = 0 ; i < 4 ; i++)
  1857.             strcpy(MacroKeys -> Keys[1][i],FunctionKeyCodes[i]);
  1858.     }
  1859.  
  1860.         /* Load the fast! macro settings. */
  1861.  
  1862.     LoadFastMacros(LastFastMacros);
  1863.  
  1864.         /* Load the speech settings. */
  1865.  
  1866.     if(!ReadIFFData(LastSpeech,&SpeechConfig,sizeof(struct SpeechConfig),'SPEK'))
  1867.     {
  1868.         SpeechConfig . Rate        = DEFRATE;
  1869.         SpeechConfig . Pitch        = DEFPITCH;
  1870.         SpeechConfig . Frequency    = DEFFREQ;
  1871.         SpeechConfig . Volume        = DEFVOL;
  1872.         SpeechConfig . Sex        = DEFSEX;
  1873.         SpeechConfig . Enabled        = FALSE;
  1874.     }
  1875.  
  1876.         /* Load the hotkey settings. */
  1877.  
  1878.     if(!ReadIFFData(LastKeys,&Hotkeys,sizeof(struct Hotkeys),'HOTK'))
  1879.     {
  1880.         strcpy(Hotkeys . termScreenToFront,    "lshift rshift return");
  1881.         strcpy(Hotkeys . BufferScreenToFront,    "control rshift return");
  1882.         strcpy(Hotkeys . SkipDialEntry,        "control lshift rshift return");
  1883.  
  1884.         Hotkeys . CommodityPriority    = 0;
  1885.         Hotkeys . HotkeysEnabled    = TRUE;
  1886.     }
  1887.  
  1888.         /* Initialize the data flow parser. */
  1889.  
  1890.     FlowInit();
  1891.  
  1892.         /* Allocate the ANSI sequence work buffer. */
  1893.  
  1894.     if(!(StripBuffer = (UBYTE *)AllocVec(Config . SerBuffSize,MEMF_ANY)))
  1895.         return(LocaleString(MSG_GLOBAL_NO_AUX_BUFFERS_TXT));
  1896.  
  1897.         /* Set up the serial driver. */
  1898.  
  1899.     if(Error = CreateSerial())
  1900.     {
  1901.         MyEasyRequest(NULL,LocaleString(MSG_GLOBAL_TERM_HAS_A_PROBLEM_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),Error);
  1902.  
  1903.         DeleteSerial();
  1904.     }
  1905.     else
  1906.     {
  1907.         if(SerialMessage)
  1908.         {
  1909.             MyEasyRequest(Window,LocaleString(MSG_GLOBAL_TERM_HAS_A_PROBLEM_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),SerialMessage);
  1910.  
  1911.             SerialMessage = NULL;
  1912.         }
  1913.     }
  1914.  
  1915.         /* Load alternative beep sound if desired. */
  1916.  
  1917.     if(Config . BeepSound[0])
  1918.         OpenSound(Config . BeepSound);
  1919.  
  1920.     if(!CreateBeep())
  1921.         return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_AUDIO_DEVICE_TXT));
  1922.  
  1923.     if(!(TimePort = (struct MsgPort *)CreateMsgPort()))
  1924.         return(LocaleString(MSG_GLOBAL_FAILED_TO_CREATE_MSGPORT_TXT));
  1925.  
  1926.     if(!(TimeRequest = (struct timerequest *)CreateIORequest(TimePort,sizeof(struct timerequest))))
  1927.         return(LocaleString(MSG_TERMINIT_FAILED_TO_CREATE_IOREQUEST_TXT));
  1928.  
  1929.     if(OpenDevice("timer.device",UNIT_VBLANK,TimeRequest,0))
  1930.         return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_TIMER_DEVICE_TXT));
  1931.  
  1932.     TimerBase = (struct Device *)TimeRequest -> tr_node . io_Device;
  1933.  
  1934.     if(ClipProcess = CreateNewProcTags(
  1935.         NP_Entry,    ClipServer,
  1936.         NP_Name,    "term clipboard process",
  1937.         NP_WindowPtr,    -1,
  1938.         NP_Priority,    20,
  1939.     TAG_DONE))
  1940.         Wait(SIGBREAKF_CTRL_C);
  1941.  
  1942.     if(!ClipProcess)
  1943.         return(LocaleString(MSG_TERMINIT_FAILED_TO_CREATE_CLIPBOARD_SERVER_TXT));
  1944.  
  1945.         /* Add the global term port. */
  1946.  
  1947.     if(!TermPort)
  1948.     {
  1949.         if(!(TermPort = (struct TermPort *)AllocVec(sizeof(struct TermPort),MEMF_PUBLIC|MEMF_CLEAR)))
  1950.             return(LocaleString(MSG_TERMINIT_FAILED_TO_CREATE_GLOBAL_PORT_TXT));
  1951.  
  1952.         NewList(&TermPort -> ExecNode . mp_MsgList);
  1953.  
  1954.         InitSemaphore(&TermPort -> OpenSemaphore);
  1955.  
  1956.         TermPort -> ExecNode . mp_Flags            = PA_IGNORE;
  1957.         TermPort -> ExecNode . mp_Node . ln_Name    = "term Port";
  1958.  
  1959.         AddPort(&TermPort -> ExecNode);
  1960.     }
  1961.  
  1962.         /* Keep another term task from removing the port. */
  1963.  
  1964.     TermPort -> HoldIt = TRUE;
  1965.  
  1966.         /* Install a new term process. */
  1967.  
  1968.     ObtainSemaphore(&TermPort -> OpenSemaphore);
  1969.  
  1970.     TermPort -> OpenCount++;
  1971.  
  1972.     TermPort -> HoldIt = FALSE;
  1973.  
  1974.     TermID = TermPort -> ID++;
  1975.  
  1976.     ReleaseSemaphore(&TermPort -> OpenSemaphore);
  1977.  
  1978.         /* Set up the ID string. */
  1979.  
  1980.     if(TermID)
  1981.         SPrintf(TermIDString,"TERM.%ld",TermID);
  1982.     else
  1983.         strcpy(TermIDString,"TERM");
  1984.  
  1985.         /* Install the hotkey handler. */
  1986.  
  1987.     SetupCx();
  1988.  
  1989.         /* Create the speech data. */
  1990.  
  1991.     CreateSpeech();
  1992.  
  1993.         /* Allocate the first few lines for the display buffer. */
  1994.  
  1995.     if(!(BufferLines = (UBYTE **)AllocVec(MaxLines * sizeof(UBYTE *),MEMF_ANY|MEMF_CLEAR)))
  1996.         return(LocaleString(MSG_TERMINIT_FAILED_TO_ALLOCATE_VIEW_BUFFER_TXT));
  1997.  
  1998.     if(!(XprIO = (struct XPR_IO *)AllocVec(sizeof(struct XPR_IO),MEMF_ANY|MEMF_CLEAR)))
  1999.         return(LocaleString(MSG_TERMINIT_FAILED_TO_CREATE_PROTOCOL_BUFFER_TXT));
  2000.  
  2001.     if(!(FileAnchor = (struct AnchorPath *)AllocVec(sizeof(struct AnchorPath),MEMF_ANY|MEMF_CLEAR)))
  2002.         return(LocaleString(MSG_TERMINIT_FAILED_TO_CREATE_ANCHOR_PATH_TXT));
  2003.  
  2004.         /* Create the download list access semaphore. */
  2005.  
  2006.     if(!(DownloadSemaphore = (struct SignalSemaphore *)AllocVec(sizeof(struct SignalSemaphore),MEMF_ANY|MEMF_CLEAR)))
  2007.         return(LocaleString(MSG_TERMINIT_FAILED_TO_ALLOCATE_SEMAPHORE_TXT));
  2008.  
  2009.     InitSemaphore(DownloadSemaphore);
  2010.  
  2011.     NewList(&SequenceList);
  2012.     NewList(&PacketHistoryList);
  2013.     NewList(&DownloadList);
  2014.     NewList(&EmptyList);
  2015.  
  2016.         /* Create the buffer access semaphore. */
  2017.  
  2018.     if(!(BufferSemaphore = (struct SignalSemaphore *)AllocVec(sizeof(struct SignalSemaphore),MEMF_ANY|MEMF_CLEAR)))
  2019.         return(LocaleString(MSG_TERMINIT_FAILED_TO_ALLOCATE_SEMAPHORE_TXT));
  2020.  
  2021.     InitSemaphore(BufferSemaphore);
  2022.  
  2023.         /* Set up the external emulation macro data. */
  2024.  
  2025.     if(!(XEM_MacroKeys = (struct XEmulatorMacroKey *)AllocVec((2 + 10 * 4) * sizeof(struct XEmulatorMacroKey),MEMF_ANY|MEMF_CLEAR)))
  2026.         return(LocaleString(MSG_TERMINIT_FAILED_TO_ALLOCATE_MACRO_KEY_DATA_TXT));
  2027.  
  2028.     strcpy(LastXprLibrary,Config . Protocol);
  2029.  
  2030.     ProtocolSetup();
  2031.  
  2032.         /* Double buffered file locking. */
  2033.  
  2034.     NewList(&DoubleBufferList);
  2035.  
  2036.     InitSemaphore(&DoubleBufferSemaphore);
  2037.  
  2038.     if(!(TermRexxPort = (struct MsgPort *)CreateMsgPort()))
  2039.         return(LocaleString(MSG_GLOBAL_FAILED_TO_CREATE_MSGPORT_TXT));
  2040.  
  2041.         /* If rexxsyslib.library opens cleanly it's time for
  2042.          * us to create the background term Rexx server.
  2043.          */
  2044.  
  2045.     if(RexxSysBase = (struct RxsLib *)OpenLibrary(RXSNAME,0))
  2046.     {
  2047.             /* Create a background process handling the
  2048.              * rexx messages asynchronously.
  2049.              */
  2050.  
  2051.         if(RexxProcess = (struct Process *)CreateNewProcTags(
  2052.             NP_Entry,    RexxServer,
  2053.             NP_Name,    "term Rexx Process",
  2054.             NP_Priority,    5,
  2055.             NP_StackSize,    8192,
  2056.             NP_WindowPtr,    -1,
  2057.         TAG_END))
  2058.         {
  2059.             Wait(SIGBREAKF_CTRL_C);
  2060.  
  2061.             if(!RexxProcess)
  2062.                 return(LocaleString(MSG_TERMINIT_UNABLE_TO_CREATE_AREXX_PROCESS_TXT));
  2063.         }
  2064.     }
  2065.  
  2066.     BinaryTransfer    = TRUE;
  2067.  
  2068.     Status        = STATUS_READY;
  2069.     Online        = FALSE;
  2070.  
  2071.     InSequence    = FALSE;
  2072.     Quiet        = FALSE;
  2073.  
  2074.     NewList(&TransferInfoList);
  2075.  
  2076.     memset(&SpecialMap[0],-1,256);
  2077.  
  2078.     for(i = 0 ; i < sizeof(SpecialKeys) / sizeof(struct SpecialKey) ; i++)
  2079.         SpecialMap[SpecialKeys[i] . Key] = i;
  2080.  
  2081.     CommandHook . h_Entry        = (APTR)CommandKey;
  2082.     CommandHook . h_SubEntry    = NULL;
  2083.     CommandHook . h_Data        = NULL;
  2084.  
  2085.         /* Create the whole display. */
  2086.  
  2087.     if(Result = CreateDisplay(TRUE))
  2088.         return(Result);
  2089.     else
  2090.         return(NULL);
  2091. }
  2092.